package booroo.basic;

import java.util.Scanner;

import booroo.service.J20_BookDBDAO;
import booroo.model.J20_BookDBVO;

public class J20_BookDBMain {
	private static final String title = "- BookDB 프로그램 -";
	private static final String menu = ">> 추가(1) 전체조회(2) ID,TITLE조회(3) 특정ID조회(4) 수정(5) 삭제(6) 종료(0) << ";
	private static final String addmsg = ">> 추가할 데이터를 Title,Publisher,Author순으로 입력하세요!";
	private static final String readmsg = ">> 조회할 데이터 번호를 입력하세요!";
	private static final String modmsg1 = ">> 수정할 데이터 번호를 입력하세요!";
	private static final String modmsg2 = ">> 수정할 데이터를 Title,Publisher,Author순으로 입력하세요!";
	private static final String delmsg = ">> 삭제할 데이터 번호를 입력하세요!";
	public static J20_BookDBDAO srv = new J20_BookDBDAO();
	public static Scanner sc = new Scanner(System.in);
	
	
	public static void main(String[] args) {
		
		while(true){
			System.out.println(title);
			System.out.println(menu);
			switch(sc.nextInt()){
			case 0: sc.close(); System.out.println("Good Bye!");System.exit(0);break; 
			case 1: newBookDB(sc, srv); break; 
			case 2: readBookDB(srv); break;
			case 3: read2BookDB(srv); break;
			case 4: read1BookDB(sc, srv); break;
			case 5: modifyBookDB(sc, srv); break;
			case 6: removeBookDB(sc, srv); break;
			}
		}
		
	}

		private static void newBookDB(Scanner sc,J20_BookDBDAO srv){
			System.out.println(addmsg);
			J20_BookDBVO bvo = new J20_BookDBVO(sc.next(),sc.next(),sc.next());
			if(srv.insertBookDB(bvo)>0){
			System.out.println("데이터가 추가 되었습니다");
			}
		}
		private static void readBookDB(J20_BookDBDAO srv){
			System.out.println(srv.selectBookDB());
		}
		private static void read1BookDB(Scanner sc,J20_BookDBDAO srv){
			System.out.println(readmsg);
			String id = sc.next();
			J20_BookDBVO bvo = new J20_BookDBVO();
			bvo.setId(id);
			System.out.println(srv.selectBookDB2(id));
				
			}
		private static void read2BookDB(J20_BookDBDAO srv){
			System.out.println(srv.selectBookDB3());
		}
				
		private static void modifyBookDB(Scanner sc,J20_BookDBDAO srv){
			System.out.println(srv.selectBookDB());
			System.out.println(modmsg1);
			String id = sc.next();
			System.out.println(modmsg2);
			J20_BookDBVO bvo = new J20_BookDBVO(sc.next(),sc.next(),sc.next());
			bvo.setId(id);
			if(srv.updateBookDB(bvo)>0){
			System.out.println(id + "번 데이터가 수정되었습니다");
			}
		}
		private static void removeBookDB(Scanner sc,J20_BookDBDAO srv){
			System.out.println(delmsg);
			System.out.println(srv.selectBookDB());
			String id = sc.next();
			if(srv.deleteBookDB(id)>0){
			System.out.println(id + "번 데이터가 삭제되었습니다");
			System.out.println(srv.selectBookDB());
			}
		
	}

}
